/*
    Copyright is LuoYuShun to 2022-2022
*/
package cn.com.laya.service.fourdemo.deals.websocket.impl;

import cn.com.laya.service.fourdemo.bean.ResultResponse;
import cn.com.laya.service.fourdemo.bean.WebSocketMessage;
import cn.com.laya.service.fourdemo.deals.websocket.WebSocketMessageHandler;
import cn.com.laya.service.fourdemo.enums.MessageTypeEnum;
import cn.com.laya.service.fourdemo.utils.WebSocketUtils;
import cn.com.laya.service.fourdemo.websocket.WebSocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

/**
 * 描述
 *
 * @author LuoYuShun
 * @since 2022-11-24
 */
@Component
@Slf4j
public class SceneWebSocketMessageHandler extends WebSocketMessageHandler {
    @Override
    protected boolean isHandler(String messageType) {
        return MessageTypeEnum.CHANGE_SCENE.getType().equals(messageType);
    }

    @Override
    protected void handlerMessage(WebSocketMessage webSocketMessage, Consumer<ResultResponse<?>> fallBackInvoke) {
        WebSocket webSocket = WebSocketUtils.getWebSocket(webSocketMessage.getAccount());
        if (!isAuthLogin(webSocketMessage, webSocket, fallBackInvoke)) {
            return;
        }
        sendMessage(webSocketMessage, fallBackInvoke, webSocket, new ConcurrentHashMap<>(1));
    }
}
